/*
 * v1.1 by tonydon site:txdnet.cn
 * netbeansIDE 7.1
 */
package cn.txdnet.txcms.admin.action;
import cn.txdnet.txcms.domain.Feedback;
import cn.txdnet.txcms.query.FeedbackQuery;
import cn.txdnet.txcms.service.FeedbackService;
import cn.txdnet.txweb.model.ModelUtil;
import cn.txdnet.txweb.model.ModelView;
import cn.txdnet.txweb.utils.BeanUtil;
import cn.txdnet.txweb.utils.Message;
import cn.txdnet.txweb.utils.WebUtil;
import javax.servlet.http.HttpServletRequest;
/**
 *
 * @author txdnet
 */
public class FeedbackAction {
    
    /*
     * 批量删除反馈信息
     */
    public ModelView delete_batch(HttpServletRequest req){
        String ids = WebUtil.getArrStr(req, "ids", null);
        if(ids==null){
            return ModelUtil.getTextModel(Message.MSG_PARAM_ERR);
        }
        int del_num = FeedbackService.deleteBatch(ids);
        if(del_num>0){
            return ModelUtil.getTextModel(del_num);
        }else{
            return ModelUtil.getTextModel(Message.MSG_FIELD_ERR);
        }
    }
    
    /*
     *  更新反馈处理状态
     */
    public ModelView update_deal_state(HttpServletRequest req){
        byte state = WebUtil.getByte(req, "state", -1);
        int msgid  = WebUtil.getInt(req, "msgid", -1);
        if(state<0 || msgid<0){
            return ModelUtil.getTextModel(Message.MSG_PARAM_ERR);
        }
        Feedback fb = new Feedback();
                 fb.setMsgid(msgid);
                 fb.setDealstate(state);
        if(FeedbackService.updateDealState(fb)){
            return ModelUtil.getTextModel(Message.MSG_SUCCESS);
        }else{
            return ModelUtil.getTextModel(Message.MSG_FAIL);
        }
    }
    
    /*
     * 列表查询
     */
    public ModelView list_factor(HttpServletRequest req) throws Exception{
        FeedbackQuery query = BeanUtil.parseRequestToBean(FeedbackQuery.class, req);
        return ModelUtil.getJsonModel(FeedbackService.queryByFactor(query));
    }
    
    /*
     * 查询反馈内容
     */
    public ModelView query_msg(HttpServletRequest req){
        int msgid = WebUtil.getInt(req, "msgid", -1);
        if(msgid<0){
            return ModelUtil.getTextModel(Message.MSG_PARAM_ERR);
        }
        String msg = FeedbackService.queryMsg(msgid);
        if(msg==null){
            return ModelUtil.getTextModel(Message.MSG_VALUE_NULL);
        }else{
            return ModelUtil.getTextModel(msg);
        }
    }
}